//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.baidu.trace.c;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.content.Context;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.os.Build.VERSION;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import com.baidu.trace.TraceJniInterface;
import com.baidu.trace.model.CoordType;
import com.baidu.trace.model.LatLng;
import com.baidu.trace.model.TraceLocation;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.TreeMap;
import java.util.regex.Pattern;

public final class e {
    private static final Pattern e = Pattern.compile("^(?!_)[a-zA-Z0-9_\\-]{1,128}");
    private static final Pattern f = Pattern.compile("[a-zA-Z0-9_\\-一-龥]{1,128}");
    private static final SimpleDateFormat g;
    private static List<ScanResult> h;
    private static List<ScanResult> i;
    private static WifiManager j;
    public static String a;
    public static String b;
    public static String c;
    public static int d;
    private static boolean k;

    public static void a(Context var0) {
        if(!k) {
            PackageManager var2 = var0.getPackageManager();
            b = var0.getApplicationInfo().loadLabel(var2).toString();
            ConnectivityManager var3 = (ConnectivityManager)var0.getSystemService("connectivity");
            String var10000;
            if(var3 == null) {
                var10000 = null;
            } else {
                NetworkInfo var1 = var3.getActiveNetworkInfo();
                if(var1 != null && var1.isAvailable()) {
                    if(1 == var1.getType()) {
                        a = "WIFI";
                    } else if(0 == var1.getType()) {
                        String var4 = var1.getSubtypeName();
                        switch(var1.getSubtype()) {
                            case 1:
                            case 2:
                            case 4:
                            case 7:
                            case 11:
                                a = "2G";
                                break;
                            case 3:
                            case 5:
                            case 6:
                            case 8:
                            case 9:
                            case 10:
                            case 12:
                            case 14:
                            case 15:
                                a = "3G";
                                break;
                            case 13:
                                a = "4G";
                                break;
                            default:
                                if(!var4.equalsIgnoreCase("TD-SCDMA") && !var4.equalsIgnoreCase("WCDMA") && !var4.equalsIgnoreCase("CDMA2000")) {
                                    a = var4;
                                } else {
                                    a = "3G";
                                }
                        }
                    }

                    var10000 = a;
                } else {
                    var10000 = null;
                }
            }

            c(var0);
            k = true;
        }
    }

    public static boolean a(String var0) {
        return TextUtils.isEmpty(var0)?false:f.matcher(var0).matches();
    }

    public static boolean b(String var0) {
        return TextUtils.isEmpty(var0)?false:e.matcher(var0).matches();
    }

    public static int a() {
        return (int)(System.currentTimeMillis() / 1000L);
    }

    public static long b() {
        return System.currentTimeMillis() / 1000L;
    }

    public static String b(Context var0) {
        try {
            TelephonyManager var2 = (TelephonyManager)var0.getSystemService("phone");
            return var2 != null?(var2.getSimSerialNumber() == null?"":var2.getSimSerialNumber()):"";
        } catch (Exception var1) {
            return "";
        }
    }

    public static String c(Context var0) {
        try {
            c = var0.getPackageName();
        } catch (Exception var1) {
            ;
        }

        return c;
    }

    public static boolean a(int var0, int var1, int var2) {
        return var0 >= var1 && var0 <= var2;
    }

    public static boolean a(LatLng var0) {
        return var0 == null?false:180.0D > Math.abs(var0.longitude) && 90.0D > Math.abs(var0.latitude);
    }

    public static long c(String var0) {
        try {
            return g.parse(var0).getTime() / 1000L;
        } catch (ParseException var1) {
            return 0L;
        }
    }

    public static String c() {
        Calendar var0 = Calendar.getInstance();
        return (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(var0.getTime());
    }

    public static void a(int var0, int var1, TreeMap<String, String> var2) {
        if(var0 > 0) {
            var2.put("page_index", String.valueOf(var0));
        }

        if(var1 > 0) {
            var2.put("page_size", String.valueOf(var1));
        }

    }

    public static boolean d(Context var0) {
        if(j == null) {
            j = (WifiManager)var0.getSystemService("wifi");
        }

        j.startScan();
        h = j.getScanResults();
        if(i != null && 0 != i.size()) {
            if(a(h, i)) {
                return true;
            } else {
                i = null;
                i = h;
                return false;
            }
        } else {
            i = h;
            return false;
        }
    }

    public static boolean a(List<ScanResult> var0, List<ScanResult> var1) {
        if(var0 != null && var1 != null) {
            int var2 = var0.size();
            int var3 = var1.size();
            int var4 = var2 + var3;
            if(var2 != 0 && var3 != 0) {
                int var5 = 0;

                int var6;
                for(var6 = 0; var6 < var2; ++var6) {
                    String var7 = ((ScanResult)var0.get(var6)).BSSID;
                    if(var7 != null) {
                        for(int var8 = 0; var8 < var3; ++var8) {
                            if(var7.equals(((ScanResult)var1.get(var8)).BSSID)) {
                                ++var5;
                                break;
                            }
                        }
                    }
                }

                var6 = var5 << 1;
                int var9 = (int)((float)var4 * 0.5F);
                if(var2 > 5 && var3 > 5) {
                    if(var6 > var9) {
                        return true;
                    } else {
                        return false;
                    }
                } else if(var5 << 1 == var4) {
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

    public static void a(TraceLocation var0) {
        double[] var1 = TraceJniInterface.wgsToBaidu(var0.getLatitude(), var0.getLongitude());
        if(var1 != null && 2 == var1.length) {
            var0.setLatitude(var1[0]);
            var0.setLongitude(var1[1]);
            var0.setCoordType(CoordType.bd09ll);
        } else {
            var0.setCoordType(CoordType.wgs84);
        }
    }

    private static double a(double var0) {
        return var0 * 3.141592653589793D / 180.0D;
    }

    public static double a(LatLng var0, LatLng var1) {
        double var2 = a(var0.latitude);
        double var4 = a(var1.latitude);
        double var6 = var2 - var4;
        double var8 = a(var0.longitude) - a(var1.longitude);
        return (double)(Math.round(2.0D * Math.asin(Math.sqrt(Math.pow(Math.sin(var6 / 2.0D), 2.0D) + Math.cos(var2) * Math.cos(var4) * Math.pow(Math.sin(var8 / 2.0D), 2.0D))) * 6378.137D * 10000.0D) / 10L);
    }

    public static boolean a(Context var0, String var1) {
        ActivityManager var3 = (ActivityManager)var0.getSystemService("activity");
        if(var3 == null) {
            return false;
        } else {
            List var4 = var3.getRunningServices(128);
            if(var4 == null) {
                return false;
            } else {
                Iterator var5 = var4.iterator();

                String var2;
                do {
                    if(!var5.hasNext()) {
                        return false;
                    }

                    var2 = ((RunningServiceInfo)var5.next()).service.getClassName().toString();
                } while(!var1.equals(var2));

                return true;
            }
        }
    }

    public static boolean e(Context var0) {
        return VERSION.SDK_INT < 23?true:0 == var0.checkSelfPermission("android.permission.ACCESS_FINE_LOCATION");
    }

    public static boolean f(Context var0) {
        if(VERSION.SDK_INT < 23) {
            return true;
        } else {
            boolean var1 = 0 == var0.checkSelfPermission("android.permission.ACCESS_WIFI_STATE");
            boolean var2 = 0 == var0.checkSelfPermission("android.permission.CHANGE_WIFI_STATE");
            return var1 && var2;
        }
    }

    public static boolean g(Context var0) {
        if(VERSION.SDK_INT < 23) {
            return true;
        } else {
            boolean var1 = 0 == var0.checkSelfPermission("android.permission.ACCESS_FINE_LOCATION");
            boolean var2 = 0 == var0.checkSelfPermission("android.permission.ACCESS_COARSE_LOCATION");
            return var1 && var2;
        }
    }

    static {
        new DecimalFormat("#0.##");
        g = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        j = null;
        a = "4G";
        b = "yingyan";
        c = "com.baidu.trace";
        d = 0;
        k = false;
    }
}
